home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / Flight Stability / Flight Stability Source / CFSApp.p < prev    next >
Encoding:
Text File  |  1995-07-09  |  5.0 KB  |  169 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CFSApp.p                                                                                                                                                                                                                }
  4. {}
  5. {        Application methods for the Flight Stability application.                                                                        }
  6. {}
  7. {        Copyright © 1995, Patrick Hew.  All rights reserved.                                                                            }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CFSApp;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, FSIntf;
  18.  
  19. implementation
  20.  
  21.     const
  22.         kExtraMasters = 4;            (* number of extra master pointer blocks *)
  23.         kRainyDay = 32000;            (* total rainy day memory reserve size     *)
  24.         kCriticalBalance = 30000;    (* portion of rainy day for critical operations *)
  25.         kToolboxBalance = 20000;    (* portion of rainy day for toolbox reserve *)
  26.  
  27.  
  28. { IFSApp }
  29. {}
  30. { Post: The flight stability application has been initialized. }
  31.  
  32.     procedure CFSApp.IFSApp;
  33.  
  34.     begin { IFSApp }
  35.         IApplication(kExtraMasters, kRainyDay, kCriticalBalance, kToolboxBalance);
  36.  
  37.         { The parameters to IApplication are the number of times to call MoreMasters,    }
  38.         { the number of bytes of heap space to reserve for monitoring                        }
  39.         { low memory situations, and the credit limit for memory requests.                }
  40.         {   Four (4) is a reasonable number of MoreMasters calls,                            }
  41.         { but you should determine a good number for your application                        }
  42.         { by observing the heap using Lightsbug,                                                }
  43.         { TMON, or Macsbug. Set this parameter to zero, give your                            }
  44.         { program a rigorous work-out, then look at the heap and count                        }
  45.         { how many master pointer blocks have been allocated. Master                        }
  46.         { pointer blocks are nonrelocatable and have a size of $100                            }
  47.         { (hex). You should call MoreMasters at least this many                                }
  48.         { times -- add a few extra just to be safe. The purpose of all                        }
  49.         { this preflighting is to prevent heap fragmentation. You                                }
  50.         { don't want the Memory Manager to call MoreMasters and                            }
  51.         { create a nonrelocatable block in the middle of your heap. By                        }
  52.         { calling MoreMasters at the very beginning of the program,                            }
  53.         { you ensure that these blocks are allocated in a group at the                        }
  54.         { bottom of the heap.                                                                        }
  55.         {   The memory reserve is a safeguard for handling low memory                    }
  56.         { conditions and is used by the GrowMemory method in                                }
  57.         { CApplication (check there for more comments). In general,                            }
  58.         { your program should never request a memory block greater                        }
  59.         { than this reserve size without explicitly checking in                                }
  60.         { advance whether there is enough free memory to satisfy the                        }
  61.         { the request.                                                                                }
  62.         {   The credit limit specifies a cut-off level for memory                                }
  63.         { requests which can tap the memory reserve. Requests larger                        }
  64.         { than this size will not use the memory reserve when the                            }
  65.         { system pleads for more memory.                                                        }
  66.  
  67.     end; { IFSApp }
  68.  
  69.  
  70. { SetUpFileParameters }
  71. {}
  72. { Post: The signature of the application has been set. }
  73.  
  74.     procedure CFSApp.SetUpFileParameters;
  75.  
  76.     begin { SetUpFileParameters }
  77.         inherited SetUpFileParameters;    { Be sure to call the default method }
  78.  
  79.         {*}
  80. {         **    Although it's not an instance variable,}
  81. {         **    this method is a good place to set the}
  82. {         **    gSignature global variable. Set this global}
  83. {         **    to your application's signature. You'll use it}
  84. {         **    to create a file (see CFile.CreateNew).}
  85. {         **}
  86. {         *}
  87.  
  88.         gSignature := '????';
  89.     end; { SetUpFileParameters }
  90.  
  91.  
  92. { MakeDesktop }
  93. {}
  94. { Post: The application has set up a desktop which allows floating windows. }
  95.  
  96.     procedure CFSApp.MakeDesktop;
  97.  
  98.     begin { MakeDesktop }
  99.         new(CFWDesktop(gDesktop));
  100.         CFWDesktop(gDesktop).IFWDesktop(SELF);
  101.     end; { MakeDesktop }
  102.  
  103.  
  104. { DoCommand }
  105. {}
  106. { Post: The command with the given command id has been acted upon. }
  107.  
  108.     procedure CFSApp.DoCommand (theCommand: longint);
  109.  
  110.     begin { DoCommand }
  111.         case theCommand of
  112.  
  113.         { Your commands go here (dummyCmd is given as an example)    }
  114.  
  115.             cmdAbout:  begin
  116.                 itsHelpDirector.DrawHelpWindow(ModeCredits);
  117.             end;    { doAbout }
  118.  
  119.             otherwise begin
  120.                 inherited DoCommand(theCommand);
  121.             end; { otherwise }
  122.  
  123.         end; { case }
  124.     end; { DoCommand }
  125.  
  126.  
  127. { StartUpAction }
  128. {}
  129. { Post: The game director has been created and its window selected. }
  130.  
  131.     procedure CFSApp.StartUpAction (numPreloads: Integer);
  132.  
  133.         var
  134.             theGameDirector: CFSGameDirector;
  135.             theHelpDirector: CFSHelpDirector;
  136.  
  137.     begin { StartupAction }
  138.         new(theGameDirector);
  139.         itsGameDirector := theGameDirector;
  140.         itsGameDirector.IFSGameDirector(SELF);
  141.         itsGameDirector.BuildWindow;
  142.         itsGameDirector.GetWindow.Select;
  143.  
  144.         new(theHelpDirector);
  145.         itsHelpDirector := theHelpDirector;
  146.         itsHelpDirector.IFSHelpDirector(SELF);
  147.         itsHelpDirector.BuildWindow;
  148.         itsHelpDirector.GetWindow.Select;
  149.  
  150.     end; { StartupAction }
  151.  
  152.  
  153. { ExitApp }
  154. {}
  155. { Post: Memory allocated by the application has been disposed of. }
  156.  
  157.     procedure CFSApp.ExitApp;
  158.  
  159.     begin { ExitApp }
  160.         { Because the game director and level documents are installed in the supervision heirarchy, }
  161.         { the default methods handle disposal. All we need to do is reset our own pointers. }
  162.  
  163.         itsGameDirector := nil;
  164.  
  165.         inherited ExitApp;
  166.     end; { ExitApp }
  167.  
  168.  
  169. end. { CFSApp }